#include <iostream>
#include <cv.h>
#include <highgui.h>

//function to be called when the slider changes 
//position and track the sliders current value

using namespace std; 

int runint = 0;
int stopint = 0;
void switchpos_run ( int position ){
	runint = position;
	}


void switchpos_stop ( int position ){
	stopint = position;
	}

int main( int argc, char **argv )
{
    CvCapture *capture = 0;
    IplImage  *frame = 0;
    int keyboard_input  = 0;
	int run_value = 0;
	int stop_value = 0;
	
	

    //intializes a camera 
    capture = cvCaptureFromCAM( 0 );
 
    //if no image tell the user
    if ( !capture ) {
        fprintf( stderr, "Webcam unavailable\n" );
        return 1;
    }
	//output window 
	const char* output = "Gui Window";

    //create a window for the gui to be displayed
    cvNamedWindow( output, CV_WINDOW_AUTOSIZE );
	
	

	//while the q on the keyboard is not pressed run loop
    while( keyboard_input != 'q' ) {
		
		//create a slider for the run function, instead of button
		cvCreateTrackbar("run", output, &run_value, 1, switchpos_run);

		//create a slider for the stop function, instead of button
		cvCreateTrackbar("stop", output, &stop_value, 1, switchpos_stop);

		//get image from camera
		frame = cvQueryFrame( capture );
 
        //if no image, break the while loop
        if( !frame ) break;
       
        //shows the image
        cvShowImage( output, frame );
 
        //waits 1 milisecond to check for input of the keyboard
        keyboard_input = cvWaitKey( 1 );
    }
 
    /* free memory */
    cvReleaseCapture( &capture );
 
    return 0;
}